package br.com.mmm.javacenter.framework.view.taglib.helper;

import org.apache.log4j.Logger;

import br.com.mmm.javacenter.framework.annotations.RenderComponent;
import br.com.mmm.javacenter.framework.configuration.IocController;
import br.com.mmm.javacenter.framework.dao.HibernateUtil;

public final class RenderFactory {
	private static Logger logger = Logger.getLogger(RenderFactory.class);
	
	public static Render getRender(Class<?> klass) {
		try {	
			for(Class<?> k:IocController.rendersBeans){
				Class<?>[] antende = ((RenderComponent) k.getAnnotation(RenderComponent.class)).value();
				for(Class<?> k2:antende){
					if(k2 == klass || k2.isAssignableFrom(klass)){
						logger.debug(k.getSimpleName() + " to " + klass.getSimpleName() );	
						return (Render) k.newInstance();
						
					}
				}
			}
			logger.debug(InputText.class.getSimpleName() + "to" + klass.getSimpleName() );
			return (Render) InputText.class.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}
}
